package Controler.Lieu;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import JDBC.Lieu_Afficher;
import JDBC.Lieu_Modifier;
import Model.Lieu;
import Model.Listes;

/**
 * Servlet implementation class Matiere_ModifierController
 */
@WebServlet("/Lieu_ModifierController")
public class Lieu_ModifierController extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Lieu_ModifierController() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		String a = request.getParameter("lieuselect");
		int idLieu = Integer.parseInt(a);
		String numero = request.getParameter("numero");
		int num = Integer.parseInt(numero);
		String rue = request.getParameter("rue");
		String complement = request.getParameter("complement");
		String cp = request.getParameter("cp");
		String ville = request.getParameter("ville");
		String b = request.getParameter("iddep");
		int idDep = Integer.parseInt(b);
		
		Lieu l = new Lieu();
		l.idLieu = idLieu;
		l.numero = num;
		l.rue = rue;
		l.complement = complement;
		l.cp = Integer.parseInt(cp);
		l.ville = ville;
		l.idDepartement = idDep;
		
		
		Lieu_Modifier modification = new Lieu_Modifier();
		modification.modifier(l);

		HttpSession session = request.getSession();
		Listes listes = (Listes) session.getAttribute("listes");
		if (listes==null)
		{
			listes = new Listes();
		}
		
		Lieu_Afficher ListeLieu = new Lieu_Afficher();
		ArrayList<Lieu> mesLieux = ListeLieu.afficher();
		listes.setMesLieux(mesLieux);
		session.setAttribute("listes", listes);
		
		String JSPURL = "Vues/Lieu/vueGRP3_tableauLieu.jsp";
		RequestDispatcher rd = request.getRequestDispatcher(JSPURL);
		rd.forward(request, response);
	}

}
